package com.kll.carolinehmibiz.presentation.presenter

import android.content.Context
import com.kll.carolinehmibiz.OperationManager
import com.kll.carolinehmibiz.model.OperateListener
import com.kll.carolinehmibiz.net.bean.GetDiseaseResponse
import com.kll.carolinehmibiz.presentation.BasePresenter
import com.kll.carolinehmibiz.presentation.listener.SelfHelpConsultationProtocol

class SelfHelpConsultationPresenter(context: Context, mView: SelfHelpConsultationProtocol.IView): BasePresenter(context), SelfHelpConsultationProtocol.IPresenter {
    private var mView: SelfHelpConsultationProtocol.IView = mView
    private var getDiseaseListIsBusying = false

    override fun getDiseaseList() {
        loadData(true)
    }

    /**
     * 加载数据
     */
    private fun loadData(isFristPage: Boolean) {
        OperationManager.getInstancce().getDiseases(isFristPage, object : OperateListener {
            override fun onSuccess(state: Int, obj: Any?) {
                getDiseaseListIsBusying = false
                if (state == 200) {
                    val data = obj as GetDiseaseResponse?
                    if(data?.list != null && data.list!!.isNotEmpty()) {
                        loadData(false)
                        mView.getDiseaseSuccessed(isFristPage, data.list!!)
                    }
                }
            }

            override fun onFail(code: Int, message: String) {
                getDiseaseListIsBusying = false
                mView.getDiseaseFailed(code, message)
            }

        })
    }
}